<%
local dsp = require "luci.dispatcher"
-%>

<fieldset class="cbi-section">
	<legend><%:Running Status%></legend>
	<fieldset class="cbi-section">
		<div class="cbi-value">
			<label class="cbi-value-title">Nginx <%:Status%></label>
			<div class="cbi-value-field" id="_nginx_status"><%:Collecting data...%></div>
		</div>
		<div class="cbi-value">
			<label class="cbi-value-title">PHP <%:Status%></label>
			<div class="cbi-value-field" id="_php_status"><%:Collecting data...%></div>
		</div>
	</fieldset>
</fieldset>

<script type="text/javascript">//<![CDATA[
	var nginx_status = document.getElementById('_nginx_status');
	var php_status = document.getElementById('_php_status');
	XHR.poll(3,'<%=dsp.build_url("admin/nas/kodexplorer/status")%>', null,
		function(x, json) {
			if (x && x.status == 200) {
				if (nginx_status) {
					nginx_status.innerHTML = json.nginx_status ? '<font color="green"><%:RUNNING%> ✓</font><input type="button" class="cbi-button cbi-input-apply" value="<%:Enter interface%>" onclick="openwebui()" />' : '<font color="red"><%:NOT RUNNING%> X</font>';
				}
				if (php_status) {
					php_status.innerHTML = json.php_status ? '<font color="green"><%:RUNNING%> ✓</font>' : '<font color="red"><%:NOT RUNNING%> X</font>';
				}
			}
		}
	);
	function openwebui(){
		var url = window.location.host+":<%=luci.sys.exec("uci -q get kodexplorer.@global[0].port"):gsub("^%s*(.-)%s*$", "%1")%>";
		window.open('http://'+url,'target','');
	}
//]]></script>